package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import common.annotation.UI_Field;
import controllers.PTcrud.Hidden;
import play.db.jpa.GenericModel;
import play.db.jpa.JPABase;

@MappedSuperclass
public class _Model extends GenericModel {

	  // 采用hibernate uuid生成器  
    @Id  
    @Column(length=36)
    // 指定生成器名称  
    @GeneratedValue(generator = "uuid2")  
    // 生成器名称，uuid生成类  
    @GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")  
	public String id;

	public String getId() {
		return id;
	}

	@Override
	public Object _key() {
		return getId();
	}

	public int _flag;
	public Date _createTime;
	@UI_Field( showName="修改时间" )
	public Date _updateTime;
	public int _adminId;

	public <T extends JPABase> T __save() {
		this._flag = 1;
		if ( StringUtils.isBlank(this.id) )
			this._createTime = new Date();
		this._updateTime = new Date();
		_save();
		return (T) this;
	}

    public <T extends JPABase> T __delete() {
    	this._flag = 0;
		this._createTime = new Date();
		this._updateTime = new Date();
		_save();
        return (T) this;
    }
	
}
